package record

import (
	"commons/util/fileUtil"
	"github.com/wonderivan/logger"
	"log"
	"runtime"
	"strconv"
	"time"
)

var runtimePath = fileUtil.GetCurrentPath() + "/" + "runtime/logs"

func Register() {
	err := fileUtil.CreateDir(runtimePath)
	if err != nil {
		panic("配置目录生成失败")
		return
	}
}

//var dayTime=time.Now().Date()
func LogInfo(msg string) {
	logFile := time.Now().Format("2006-01-02") + "-info.log"
	_, file, line, _ := runtime.Caller(1)
	msg1 := "时间：" + time.Now().Format("2006-01-02 00:00:00") + "，文件：" + file + "，行数：" + strconv.Itoa(line) + "，原因：" + msg + "\r\n"
	fileUtil.Write(msg1, runtimePath+"/"+logFile)
	logger.Info(msg)
}

func LogError(msg string) {
	logFile := time.Now().Format("2006-01-02") + "-error.log"
	_, file, line, _ := runtime.Caller(1)
	msg1 := "时间：" + time.Now().Format("2006-01-02 00:00:00") + "文件：" + file + "，行数：" + strconv.Itoa(line) + "，原因：" + msg + "\r\n"
	fileUtil.Write(msg1, runtimePath+"/"+logFile)
	_ = log.Output(1, "[ERROR] ["+file+":"+strconv.Itoa(line)+"]"+msg)
}
